﻿using System;
using System.ComponentModel;
using System.Xml.Serialization;
using tjb.Utility.Config;

namespace tjb.Utility.Gather
{
    /// <summary>
    /// Represents a Gather rule.  A Gather rule is composed of a pattern to search for and a string to replace
    /// the pattern with (if matched).
    /// </summary>
    [Serializable()]
    public class Rule : IComparable<Rule>, IEquatable<Rule>
    {

        #region 属性

        /// <summary>
        /// 执行序号
        /// </summary>
        public int serialNo
        {
            get;
            set;
        }
        /// <summary>
        /// 规则开始字符
        /// </summary> 
        public CDATA Primality
        {
            get;
            set;
        }
        /// <summary>
        /// 规则结束字符
        /// </summary>
        public CDATA End
        {
            get;
            set;
        }
        /// <summary>
        /// 新字符串或者正则结果
        /// </summary>
        public CDATA NewStr
        {
            get;
            set;
        }
        /// <summary>
        /// 匹配表达式
        /// </summary>
        public CDATA RegexPattern
        {
            get;
            set;
        }

        /// <summary>
        /// 操作符
        /// </summary>
        [XmlAttribute("OperateType")]
        public OperateType Operate
        {
            get;
            set;
        }

        /// <summary>
        /// 是否包含头
        /// </summary>
        [XmlAttribute("IncludedHead")]
        public bool IncludedHead
        {
            get;
            set;
        }
        /// <summary>
        /// 是否包含尾部
        /// </summary>
        [XmlAttribute("IncludedTail")]
        public bool IncludedTail
        {
            get;
            set;
        }
        #endregion




        #region IEquatable<Rule> 成员

        bool IEquatable<Rule>.Equals(Rule other)
        {
            return other != null && this.serialNo == other.serialNo;
        }

        #endregion

        #region IComparable<Rule> 成员

        int IComparable<Rule>.CompareTo(Rule other)
        {
            return other != null ? this.serialNo - other.serialNo : 1;
        }

        #endregion
    }
}
